<template>
  <view>
    <!-- 专辑背景 开始 -->
    <view class="album_bg">
      <image :src="album.cover" mode="widthFix" />
      <view class="album_info">
        <view class="album_name">{{ album.name }}</view>
        <view class="album_btn">关注专辑</view>
      </view>
    </view>
    <!-- 专辑背景 结束 -->

    <!-- 专辑作者 开始 -->
    <view class="album_author">
      <view class="album_author_info">
        <image :src="album.user.avatar" mode="widthFix" />
        <view class="author_name">{{ album.user.name }}</view>
      </view>
      <view class="album_author_desc">
        <text>{{ album.desc }}</text>
      </view>
    </view>
    <!-- 专辑作者 结束 -->

    <!-- 列表 开始 -->
    <view class="album_list">
      <!-- <view class="album_item" v-for="item in wallpaper" :key="item.id">
        <image
          :src="item.thumb + item.rule.replace('$<Height>', 360)"
          mode="widthFix"
        />
      </view> -->
      <view
        class="album_item"
        v-for="(item, index) in wallpaper"
        :key="item.id"
      >
        <go-detail :list="wallpaper" :index="index">
          <image :src="item.thumb" mode="aspectFill" />
        </go-detail>
      </view>
    </view>
    <!-- 列表 结束 -->
  </view>
</template>

<script>
import goDetail from '@/components/goDetail'

export default {
  data() {
    return {
      params: {
        limit: 30,
        order: 'new',
        skip: 0,
        // 1 返回值中有 album对象 表示第一次请求
        // 0 返回值中只有 wallpaper数组 不是第一次请求
        first: 1,
      },
      id: -1,
      album: {},
      wallpaper: [
        {
          id: 1,
          thumb:
            'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1116427792,3866915859&fm=15&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://dss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2244290797,640176041&fm=26&gp=0.jpg',
          },
          atime: 1511308932,
          rank: 999,
        },
        {
          id: 2,
          thumb:
            'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2961100896,2697441296&fm=15&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 1621838819,
          rank: 998,
        },
        {
          id: 3,
          thumb:
            'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=175152827,291441337&fm=15&gp=0.jpg',
          user: {
            name: '人工智障',
            avatar:
              'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3446394286,4159104495&fm=26&gp=0.jpg',
          },
          atime: 1619246819,
          rank: 520,
        },
        {
          id: 4,
          thumb:
            'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3232466287,4226311267&fm=26&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 511308932,
          rank: 1314,
        },
        {
          id: 5,
          thumb:
            'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3197184239,921790899&fm=11&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 1001308932,
          rank: 233,
        },
        {
          id: 6,
          thumb:
            'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=693984621,1124251110&fm=26&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 1981308932,
          rank: 666,
        },
        {
          id: 7,
          thumb:
            'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3226929334,2611245212&fm=26&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 159841932,
          rank: 123,
        },
        {
          id: 8,
          thumb:
            'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3914394085,2993803159&fm=11&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 151120932,
          rank: 110,
        },
        {
          id: 9,
          thumb:
            'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2324746735,2647190352&fm=26&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 150018932,
          rank: 120,
        },
        {
          id: 10,
          thumb:
            'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1229762590,119568568&fm=15&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 1511300032,
          rank: 10,
        },
        {
          id: 11,
          thumb:
            'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2009793488,961985981&fm=26&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 1211308932,
          rank: 888,
        },
        {
          id: 12,
          thumb:
            'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3458905319,2009577059&fm=26&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 1011308932,
          rank: 6,
        },
        {
          id: 13,
          thumb:
            'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3076213901,312780734&fm=15&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 15113032,
          rank: 100,
        },
        {
          id: 14,
          thumb:
            'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3188377849,2340719433&fm=15&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 151108932,
          rank: 200,
        },
        {
          id: 15,
          thumb:
            'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=616767308,94552610&fm=26&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 15308932,
          rank: 333,
        },
        {
          id: 16,
          thumb:
            'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2548127795,4104861996&fm=26&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 1811308932,
          rank: 564,
        },
        {
          id: 17,
          thumb:
            'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1588105102,4289153942&fm=15&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 111308932,
          rank: 789,
        },
        {
          id: 18,
          thumb:
            'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=92601674,178289694&fm=11&gp=0.jpg',
          user: {
            name: '甘雨',
            avatar:
              'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1391930116,2035308332&fm=26&gp=0.jpg',
          },
          atime: 15113089,
          rank: 465,
        },
      ],
      hasMore: true,
    }
  },
  components: {
    goDetail,
  },
  onLoad(options) {
    this.id = options.id
    this.getList()
  },
  // 页面触底 上拉加载下一页事件
  onReachBottom() {
    if (this.hasMore) {
      this.params.first = 0
      this.params.skip += this.params.limit
      this.getList()
    } else {
      uni.showToast({
        title: '没有更多数据了',
        icon: 'none',
      })
    }
  },
  methods: {
    getList() {
      this.request({
        url: `http://service.picasso.adesk.com/v1/wallpaper/album/${this.id}/wallpaper`,
        data: this.params,
      }).then((result) => {
        if (Object.keys(this.album).length === 0) {
          this.album = result.res.album
        }
        if (result.res.wallpaper.length === 0) {
          this.hasMore = false
          // uni.showToast({
          //   title: '没有更多数据了',
          //   icon: 'none',
          // })
          return
        }
        this.wallpaper = [...this.wallpaper, ...result.res.wallpaper]
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.album_bg {
  position: relative;
  image {
  }
  .album_info {
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    height: 80rpx;
    align-items: center;
    color: #fff;
    padding: 0 15rpx;
    .album_name {
      font-size: 40rpx;
    }
    .album_btn {
      background-color: $color;
      width: 152rpx;
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 10rpx;
    }
  }
}

.album_author {
  padding: 10rpx;
  .album_author_info {
    padding: 10rpx 0;
    display: flex;
    image {
      width: 50rpx;
    }

    .author_name {
      color: #000;
      margin-left: 15rpx;
    }
  }

  .album_author_desc {
  }
}

.album_list {
  display: flex;
  flex-wrap: wrap;
  padding-bottom: 30rpx;
  .album_item {
    width: 33.33%;
    border: 3rpx solid #fff;
    image {
      height: 160rpx;
    }
  }
}
</style>